package leetcode.秋招.拼多多;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/22 18:55
 * @description：
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int i = 0; i < T; i++) {
            int count = 0;
            int P = in.nextInt();
            int Q = in.nextInt();
            while (Q != P) {
                if (Q >= 2 * P) {
                    P *= 2;
                    count++;
                } else if (Q == P + 1) {
                    P += 1;
                    count++;
                } else if (Q <= P - 2) {
                    int num = P - Q;
                    count += num / 2;
                    P -= (num / 2) * 2;
                } else if (Q < P) {
                    int num = P - Q;
                    count += num;
                    P += num;
                }
            }
            System.out.println(count);
        }
    }
}
